<?php

/*
 * Copyright (C) 2014 vlasta81
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Description of Config
 *
 * @author vlasta81
 */

namespace system;

final class config {

    const CONFIG_EXT = '.cfg';
    const CONFIG_DIR = './System/Config/';

    public function __construct() {
        
    }

    static function newConfig($file) {
        if (file_exists(self::CONFIG_DIR . $file . self::CONFIG_EXT)) : throw new Exception('Soubor s nastavením již existuje!');
        else : touch(self::CONFIG_DIR . $file . self::CONFIG_EXT);
        endif;
    }

    static function addConfig($file, $data) {
        if (file_exists(self::CONFIG_DIR . $file . self::CONFIG_EXT)) : file_put_contents(self::CONFIG_DIR . $file . self::CONFIG_EXT, serialize($data), LOCK_EX);
        else : throw new Exception('Soubor s nastavením neexistuje!');
        endif;
    }

    static function getConfig($file) {
        if (!file_exists(self::CONFIG_DIR . $file . self::CONFIG_EXT)) : throw new Exception('Soubor s nastavením neexistuje!');
        else : return unserialize(file_get_contents(self::CONFIG_DIR . $file . self::CONFIG_EXT));
        endif;
        
    }

    static function delConfig($file) {
        if (file_exists(self::CONFIG_DIR . $file . self::CONFIG_EXT)) : unlink(self::CONFIG_DIR . $file . self::CONFIG_EXT);
        else : throw new Exception('Soubor s nastavením neexistuje!');
        endif;
    }

}
